//
//  FacilityLocation.m
//  YOGProj
//
//  Created by liyun on 14-7-1.
//  Copyright (c) 2014年 liyun. All rights reserved.
//

#import "FacilityLocation.h"
#import <MAMapKit/MAMapKit.h>
#import "MacroDefinition.h"

@interface FacilityLocation ()

@property (strong,nonatomic) MAMapView *mapView;
@property MAPointAnnotation *pointAnnotation;

@end

@implementation FacilityLocation

@synthesize latitude,longitude;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSLog(@"latitude-->%f",latitude);
    NSLog(@"longitude-->%f",longitude);
    [self initAnnotations];

    
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, 30, 30);
    [button setBackgroundImage:[UIImage imageNamed:NAVIGATION_BACK_IMAGE] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(navigationShowLeft) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItemleft=[[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItem=barItemleft;
    
    self.mapView = [[MAMapView alloc]initWithFrame:self.view.frame];
    self.mapView.delegate = self;
    self.mapView.showsUserLocation = YES;
    [self.mapView addAnnotation:self.pointAnnotation];
    [self.mapView selectAnnotation:self.pointAnnotation animated:YES];
    [self.view addSubview:self.mapView];
    
    [self.mapView setZoomLevel:13 animated:YES];
}


//-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation{
//    MAPinAnnotationView *annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:self.pointAnnotation reuseIdentifier:@"pointReuseIdetifier"];
//    annotationView.canShowCallout            = YES;
//    annotationView.animatesDrop              = YES;
//    annotationView.draggable                 = YES;
//    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//    annotationView.pinColor = MAPinAnnotationColorRed;
//    return annotationView;
//}


-(void)initAnnotations{
    self.pointAnnotation = [[MAPointAnnotation alloc]init];
    self.pointAnnotation.coordinate = CLLocationCoordinate2DMake(latitude, longitude);
}

//- (id)init
//{
//    self = [super init];
//    if (self)
//    {
//
//    }
//    
//    return self;
//}


-(void)navigationShowLeft{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
